<?php

/* Widgetable Functions  */

if ( function_exists('register_sidebar') )
  register_sidebar(array(
    'ID' => 'homepage',
    'name'=>'Homepage Sidebar',
    'before_widget' => '<div class="sidebox-top"></div><div class="sidebox"><div id="%1$s" class="widgets %2$s">',
    'after_widget' => '</div></div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>'
  ));

if ( function_exists('register_sidebar') )
  register_sidebar(array(
    'ID' => 'homepagebox1',
   'name'=>'Homepage Box 1',
      'before_widget' => '<div  id="%1$s" class="widgets  %2$s">',
      'after_widget' => '</div>',
      'before_title' => '<h3>',
      'after_title' => '</h3>'
  ));

if ( function_exists('register_sidebar') )
  register_sidebar(array(
    'ID' => 'homepagebox2',
   'name'=>'Homepage Box 2',
      'before_widget' => '<div  id="%1$s" class="widgets">',
      'after_widget' => '</div>',
      'before_title' => '<h3>',
      'after_title' => '</h3>'
  ));
if ( function_exists('register_sidebar') )  
  register_sidebar(array(
    'ID' => 'sidebar',
    'name'=>'General Sidebar',
    'before_widget' => '<div class="sidebox-top"></div><div class="sidebox"><div id="%1$s" class="widgets %2$s">',
    'after_widget' => '</div></div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>'
  ));

if ( function_exists('register_sidebar') )
  register_sidebar(array(
    'name'=>'About Page',
    'before_widget' => '<div class="sidebox-top"></div><div class="sidebox"><div id="%1$s" class="widgets %2$s">',
    'after_widget' => '</div></div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>'
  )); 
if ( function_exists('register_sidebar') )
  register_sidebar(array(
    'name'=>'Services Page',
    'before_widget' => '<div class="sidebox-top"></div><div class="sidebox"><div id="%1$s" class="widgets %2$s">',
    'after_widget' => '</div></div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>'
  )); 
if ( function_exists('register_sidebar') )
  register_sidebar(array(
    'name'=>'Blog Sidebar',
    'before_widget' => '<div class="sidebox-top"></div><div class="sidebox"><div id="%1$s" class="widgets %2$s">',
    'after_widget' => '</div></div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>'
  ));
if ( function_exists('register_sidebar') )
  register_sidebar(array(
    'name'=>'Single Post',
    'before_widget' => '<div class="sidebox-top"></div><div class="sidebox"><div id="%1$s" class="widgets %2$s">',
    'after_widget' => '</div></div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>'
  ));
 if ( function_exists('register_sidebar') )
  register_sidebar(array(
    'name'=>'Contact Sidebar',
    'before_widget' => '<div class="sidebox-top"></div><div class="sidebox"><div id="%1$s" class="widgets %2$s">',
    'after_widget' => '</div></div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>'
  ));   

/* Testimonial Widget */
class Testimonial_Widget extends WP_Widget {
  function Testimonial_Widget() {
    $widgets_opt = array('description'=>'Testimonial Centita Theme Widget');
    parent::WP_Widget(false,$name= "Centita Testimonial",$widgets_opt);
  }
  
  function form($instance) {
    global $post;
    
    $catid = esc_attr($instance['catid']);
    $testititle = esc_attr($instance['testititle']);
    $numtesti = esc_attr($instance['numtesti']);
    
    $categories_list = get_categories('hide_empty=0');
    
    $categories = array();
    foreach ($categories_list as $catlist) {
    	$categories[$catlist->cat_ID] = $catlist->cat_name;
    }

  ?>
    <p><label for="testititle"><?php echo __('Title','centita');?>:
  		<input id="<?php echo $this->get_field_id('testititle'); ?>" name="<?php echo $this->get_field_name('testititle'); ?>" type="text" class="widefat" value="<?php echo $testititle;?>" /></label></p>  
	 <p><small><?php echo __('Please select category for Testimonial.','centita');?></small>
		<select  name="<?php echo $this->get_field_name('catid'); ?>"  id="<?php echo $this->get_field_id('catid'); ?>" >
			<?php foreach ($categories as $opt => $val) { ?>
		<option value="<?php echo $opt ;?>" <?php if ( $catid  == $opt) { echo ' selected="selected" '; }?>><?php echo $val; ?></option>
		<?php } ?>
		</select>
		</label></p>	
    <p><label for="numtesti"><small><?php echo __('Number to display:','centita');?></small>
  		<input id="<?php echo $this->get_field_id('numtesti'); ?>" name="<?php echo $this->get_field_name('numtesti'); ?>" type="text" class="widefat" value="<?php echo $numtesti;?>" /></label></p>
    <?php    
  } 
  
  function update($new_instance, $old_instance) {
    return $new_instance;
  }
  
  function widget( $args, $instance ) {
    global $post,$ID;
    
    extract($args);
    
    $catid = apply_filters('catid',$instance['catid']);
    $testititle = apply_filters('testititle',$instance['testititle']);
    $numtesti = apply_filters('numtesti',$instance['numtesti']);    
    
    if ($testititle == "") $testititle = __("Testimonials",'centita');
    if ($numtesti == "") $numtesti = 2;
    
    $testis = new WP_Query('cat='.$catid.'&showposts='.$numtesti);
    ?>
    <?php if ($ID == "homepagebox1" || $ID == "homepagebox2") { ?>
      <div class="box-main">
      <div class="sidebox-top"></div>
  		<div id="testimonials" class="scroll clearfix">
    <?php } else { ?>
      <div class="sidebox-top"></div>
  		<div id="testimonials" class="scroll clearfix">
    <?php } ?>
  	<?php echo $before_title.'<a href="'.get_category_link($catid).'">'.$testititle.'</a>'.$after_title;?>
  	<ul>
    <?php 
    while ( $testis->have_posts() ) : $testis->the_post();    
    ?>
    <li>
        <blockquote>
				<?php excerpt(25);?> 
				</blockquote><br />
        <strong><?php the_title();?></strong>
      </li>                  
    <?php endwhile;?>
  	</ul>
    <ol>
      <li class="previous"><a href="#">Previous</a></li>
      <li class="next"><a href="#">Next</a></li>
    </ol>
  	<?php if ($ID == "homepagebox1" || $ID == "homepagebox2") echo '</div></div>'; else echo '</div>'; ?>
	
   <?php
   wp_reset_query(); 
  } 
}

add_action('widgets_init', create_function('', 'return register_widget("Testimonial_Widget");'));

/* Office Adress Widget */
class OfficeAdress_Widget extends WP_Widget {
  function OfficeAdress_Widget() {
    $widgets_opt = array('description'=>'Office Adress Centita Theme Widget');
    parent::WP_Widget(false,$name= "Centita Office Adress",$widgets_opt);
  }
  
  function form($instance) {
    global $post;
    
    $contact_title = esc_attr($instance['contact_title']);
    $contact_email = esc_attr($instance['contact_email']);
    $contact_phone = esc_attr($instance['contact_phone']);
    $contact_address = esc_attr($instance['contact_address']);
    $contact_desc = esc_attr($instance['contact_desc']);    
    
  ?>
  <p><label for="contact_title"><?php echo __('Title','centita');?>:
  		<input id="<?php echo $this->get_field_id('contact_title'); ?>" name="<?php echo $this->get_field_name('contact_title'); ?>" type="text" class="widefat" value="<?php echo $contact_title;?>"/></label></p>
  <p><label for="contact_phone"><?php echo __('Phone','centita');?>:
  		<input id="<?php echo $this->get_field_id('contact_phone'); ?>" name="<?php echo $this->get_field_name('contact_phone'); ?>" type="text" class="widefat" value="<?php echo $contact_phone;?>" /></label></p>
  <p><label for="contact_email"><?php echo __('Email','centita');?>:
  		<input id="<?php echo $this->get_field_id('contact_email'); ?>" name="<?php echo $this->get_field_name('contact_email'); ?>" type="text" class="widefat" value="<?php echo $contact_email;?>" /></label></p>  	        	
  <p><label for="contact_address"><?php echo __('Address','centita');?>:</label>
		<textarea id="<?php echo $this->get_field_id('contact_address'); ?>" name="<?php echo $this->get_field_name('contact_address'); ?>" class="widefat" rows="6" cols="20" ><?php echo $contact_address;?></textarea></p>
<p><label for="contact_desc"><?php echo __('Short Description','centita');?>:</label>
		<textarea id="<?php echo $this->get_field_id('contact_desc'); ?>" name="<?php echo $this->get_field_name('contact_desc'); ?>"  class="widefat" rows="6" cols="20" ><?php echo $contact_desc;?></textarea></p>
    <?php    
  } 
  
  function update($new_instance, $old_instance) {
    return $new_instance;
  }
  
  function widget( $args, $instance ) {
    global $post;
    
    extract($args);
    
    $contact_title = apply_filters('contact_title',$instance['contact_title']);
    
    echo $before_widget;
    
    $info_phone = get_option('centita_info_phone');
    $info_fax = get_option('centita_info_fax');
    $info_address = get_option('centita_info_address');
    $info_website = get_option('centita_info_website');
    $info_email = get_option('centita_info_email');
    $info_latitude = get_option('centita_info_latitude');
    $info_longitude = get_option('centita_info_longitude');
    $replace_char= array(",");
    
    if ($contact_title == "") $contact_title =__("Our Detail Contact",'centita');
    ?>
    
    <script type="text/javascript">
    jQuery(document).ready(function($) {
    	jQuery("#contactmap").gMap({
    	    zoom: 15,
    	    markers:[{
    	    	address: "",
    			  latitude: <?php echo $info_latitude;?>,
    	    	longitude: <?php echo $info_longitude;?>,
    	    	html: "<?php echo str_replace($replace_char,'<br/>',$info_address);?>",
    	    	popup: true
    		}],
    		controls: [],
    		maptype: G_NORMAL_MAP,
    	  scrollwheel:true
    	});
    });
    </script>
    
  	<?php echo $before_title.$contact_title.$after_title;?>
    <div id="contactmap"></div>
     <div id="address">
     <ul>
        <li class="mail"><a href="mailto:<?php echo $info_email;?>"><?php echo $info_email;?></a></li>
        <li class="phone"><?php echo ($info_phone) ? $info_phone : $info_phone;?></li>
        <li class="address"><?php if ($info_address!="")  echo stripslashes($info_address);?></li>
     </ul>
  	</div>
   <?php
   echo $after_widget;
  } 
}

add_action('widgets_init', create_function('', 'return register_widget("OfficeAdress_Widget");'));

/* Office Adress Widget */
class NewsLetter_Widget extends WP_Widget {
  function NewsLetter_Widget() {
    $widgets_opt = array('description'=>'NewsLetter for Centita Theme Widget');
    parent::WP_Widget(false,$name= "Centita NewsLetter",$widgets_opt);
  }
  
  function form($instance) {
    global $post;

		$newsletter_title = esc_attr($instance['newsletter_title']);
		$feedburner_id = esc_attr($instance['feedburner_id']);
		$newsletter_desc = esc_attr($instance['newsletter_desc']);
    
  ?>
  <p><label for="newsletter_title"><?php echo __('Title','centita');?>:
  		<input id="<?php echo $this->get_field_id('newsletter_title'); ?>" name="<?php echo $this->get_field_name('newsletter_title'); ?>" type="text" class="widefat" value="<?php echo $newsletter_title;?>"/></label></p>
  <p><label for="feedburner_id"><?php echo __('Feedburner ID','centita');?>:
  		<input id="<?php echo $this->get_field_id('feedburner_id'); ?>" name="<?php echo $this->get_field_name('feedburner_id'); ?>" type="text" class="widefat" value="<?php echo $feedburner_id;?>" /></label></p>
<p><label for="newsletter_desc"><?php echo __('Short Description','centita');?>:</label>
		<textarea id="<?php echo $this->get_field_id('newsletter_desc'); ?>" name="<?php echo $this->get_field_name('newsletter_desc'); ?>"  class="widefat" rows="6" cols="20" ><?php echo $newsletter_desc;?></textarea></p>
    <?php    
  } 
  
  function update($new_instance, $old_instance) {
    return $new_instance;
  }
  
  function widget( $args, $instance ) {
    global $post;
    
    extract($args);
    
		$newsletter_title = apply_filters('newsletter_title',$instance['newsletter_title']);
		$feedburner_id = apply_filters('feedburner_id',$instance['feedburner_id']);
		$newsletter_desc = apply_filters('newsletter_desc',$instance['newsletter_desc']);
		if ($feedburner_id == "") $feedburner_id = __('Newsletter','centita');
    ?>
    <div class="sidebox-top"></div>
    <div class="sidebox">
  	<?php echo $before_title.$newsletter_title.$after_title;?>
    <p><?php echo stripslashes($newsletter_desc);?></p>
    <form action="http://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow" onsubmit="window.open('http://feedburner.google.com/fb/a/mailverify?uri=<?php echo $feedburner_id;?>', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true"  id="newsletter">
    <fieldset>
      <input type="hidden" value="<?php echo $feedburner_id;?>" name="uri"/>
      <input type="hidden" value="<?php bloginfo('name'); ?>" name="title"/>
      <input type="hidden" name="loc" value="en_US"/>
      <input name="email" type="text" class="inputbox01"  value="<?php echo __('enter your email address','centita');?>"  onblur="if(this.value=='') this.value='<?php echo __('enter your email address','centita');?>';" onfocus="if(this.value=='<?php echo __('enter your email address','centita');?>') this.value='';" />
      <input type="image" src="<?php echo get_template_directory_uri();?>/images/but-send.gif" class="but" />
      </fieldset>
    </form>  	
	</div><!-- end of sidebox -->
   <?php
  } 
}

add_action('widgets_init', create_function('', 'return register_widget("NewsLetter_Widget");'));

/* Featured Project Widget */
class FeaturedProject_Widget extends WP_Widget {
  function FeaturedProject_Widget () {
    $widgets_opt = array('description'=>'Featured Project Centita Theme Widget');
    parent::WP_Widget(false,$name= "Centita Featured Project",$widgets_opt);
  }
  
  function form($instance) {
    global $post;
    
    $portotitle = esc_attr($instance['portotitle']);
    $numporto = esc_attr($instance['numporto']);
    
    $categories_list = get_categories('hide_empty=0');
    
    $categories = array();
    foreach ($categories_list as $catlist) {
    	$categories[$catlist->cat_ID] = $catlist->cat_name;
    }

  ?>
    <p><label for="portotitle"><?php echo __('Title','centita');?>:
  		<input id="<?php echo $this->get_field_id('portotitle'); ?>" name="<?php echo $this->get_field_name('portotitle'); ?>" type="text" class="widefat" value="<?php echo $portotitle;?>" /></label></p>	
    <p><label for="numporto"><small><?php echo __('Number to display','centita');?>:</small>
  		<input id="<?php echo $this->get_field_id('numporto'); ?>" name="<?php echo $this->get_field_name('numporto'); ?>" type="text" class="widefat" value="<?php echo $numporto;?>" /></label></p>
    <?php    
  } 
  
  function update($new_instance, $old_instance) {
    return $new_instance;
  }
  
  function widget( $args, $instance ) {
    global $post, $ID;
    
    extract($args);
    
    $portotitle = apply_filters('portotitle',$instance['portotitle']);
    $numporto = apply_filters('numporto',$instance['numporto']);    
    
    if ($portotitle == "") $portotitle = __("Featured Project",'centita'); 
    if ($numporto == "") $numporto = 2;
    
    if (post_type_exists('portfolio')) {
      query_posts(array( 'post_type' => 'portfolio', 'showposts' => $numporto,'orderby'=>'rand'));
    } 
    ?>
    <?php if ($ID == "homepagebox1" || $ID == "homepagebox2") { ?>
      <div class="box-main">
      <div class="sidebox-top"></div>
      <div class="sidebox">
    <?php } else { ?>
    <div class="sidebox-top"></div>
		<div class="sidebox">
		<?php } ?>
  	
    <?php echo $before_title.$portotitle.$after_title;?>
    
    <?php while ( have_posts() ) : the_post();?>
    
    <?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {?>
        <img src="<?php echo get_template_directory_uri();?>/timthumb.php?src=<?php echo thumb_url();?>&amp;h=60&amp;w=60&amp;zc=1" alt="" class="imgleft" />
    <?php } ?>
    <strong><a href="<?php the_permalink();?>"><?php the_title();?></a></strong><br />
      <p><?php the_excerpt();?></p>
      <div class="clr"></div><br />
    <?php endwhile;?>
    <?php wp_reset_query();?>
    <?php if ($ID == "homepagebox1" || $ID == "homepagebox2") echo '</div></div>'; ?>
	</div>
   <?php
  } 
}

add_action('widgets_init', create_function('', 'return register_widget("FeaturedProject_Widget");'));

/* Latest News Widget */
class LatestNews_Widget extends WP_Widget {
  function LatestNews_Widget() {
    $widgets_opt = array('description'=>'Latest News Centita Theme Widget');
    parent::WP_Widget(false,$name= "Centita Latest News",$widgets_opt);
  }
  
  function form($instance) {
    global $post;
    
    $newsid = esc_attr($instance['newsid']);
    $newstitle = esc_attr($instance['newstitle']);
    $numnews = esc_attr($instance['numnews']);
    
    $categories_list = get_categories('hide_empty=0');
    
    $categories = array();
    foreach ($categories_list as $catlist) {
    	$categories[$catlist->cat_ID] = $catlist->cat_name;
    }

  ?>
    <p><label for="newstitle"><?php echo __('Title','centita');?>:
  		<input id="<?php echo $this->get_field_id('newstitle'); ?>" name="<?php echo $this->get_field_name('newstitle'); ?>" type="text" class="widefat" value="<?php echo $newstitle;?>" /></label></p>  
	 <p><small><?php echo __('Please select category for News.','centita');?></small>
		<select  name="<?php echo $this->get_field_name('newsid'); ?>"  id="<?php echo $this->get_field_id('newsid'); ?>" >
			<?php foreach ($categories as $opt => $val) { ?>
		<option value="<?php echo $opt ;?>" <?php if ( $newsid  == $opt) { echo ' selected="selected" '; }?>><?php echo $val; ?></option>
		<?php } ?>
		</select>
		</label></p>	
    <p><label for="numnews"><small><?php echo __('Number to display','centita');?>:</small>
  		<input id="<?php echo $this->get_field_id('numnews'); ?>" name="<?php echo $this->get_field_name('numnews'); ?>" type="text" class="widefat" value="<?php echo $numnews;?>" /></label></p>
    <?php    
  } 
  
  function update($new_instance, $old_instance) {
    return $new_instance;
  }
  
  function widget( $args, $instance ) {
    global $post, $ID;
    
    extract($args);
    
    $newsid = apply_filters('newsid',$instance['newsid']);
    $newstitle = apply_filters('newstitle',$instance['newstitle']);
    $numnews = apply_filters('numnews',$instance['numnews']);    
    
    if ($newstitle == "") $newstitle = __("Latest News",'centita');
    if ($numnews == "") $numnews = 2;
    
    $latestnews = new WP_Query('cat='.$newsid.'&showposts='.$numnews);
    ?>
    <?php if ($ID == "homepagebox1" || $ID == "homepagebox2") { ?>
      <div class="box-main">
      <div class="sidebox-top"></div>
  		<div id="latest-news" class="scroll clearfix">
    <?php } else { ?>
      <div class="sidebox-top"></div>
  		<div id="latest-news" class="scroll clearfix">
    <?php } ?>
  	<?php echo $before_title.$newstitle.$after_title;?>
  	<ul>
    <?php 
    while ( $latestnews->have_posts() ) : $latestnews->the_post();    
    ?>
      <li>
        <a href="<?php the_permalink();?>">
        <strong><?php the_title();?></strong></a>
        <div class="clr"></div>
        <span style="margin-bottom:8px;"><?php the_time( get_option('date_format') ); ?></span>
        <div class="clr"></div>
        <?php the_excerpt();?>
      </li>                  
		<?php endwhile;?>
    <?php wp_reset_query();?>
  	</ul>
    <ol>
      <li class="previous"><a href="#">Previous</a></li>
      <li class="next"><a href="#">Next</a></li>
    </ol>
	 </div>
	<?php if ($ID == "homepagebox1" || $ID == "homepagebox2") echo '</div>'; ?>
   <?php
  } 
}

add_action('widgets_init', create_function('', 'return register_widget("LatestNews_Widget");'));

/* Company Info Widget */
class CompanyInfo_Widget extends WP_Widget {
  function CompanyInfo_Widget() {
    $widgets_opt = array('description'=>'Company Info Theme Widget');
    parent::WP_Widget(false,$name= "Centita Company Info",$widgets_opt);
  }
  
  function form($instance) {
    global $post;
    
    $companyinfotitle = esc_attr($instance['companyinfotitle']);
    $aboutpid = esc_attr($instance['aboutpid']);
    $servicespid = esc_attr($instance['servicespid']);
    
		$pages = get_pages();
		$listpages = array();
		foreach ($pages as $pagelist ) {
		   $listpages[$pagelist->ID] = $pagelist->post_title;
		}    

  ?>
    <p><label for="companyinfotitle"><?php echo __('Title','centita');?>:
  		<input id="<?php echo $this->get_field_id('companyinfotitle'); ?>" name="<?php echo $this->get_field_name('companyinfotitle'); ?>" type="text" class="widefat" value="<?php echo $companyinfotitle;?>" /></label></p>
	<p><small><?php echo __('Your About Page.','centita');?></small>
		<select  name="<?php echo $this->get_field_name('aboutpid'); ?>"  id="<?php echo $this->get_field_id('aboutpid'); ?>" >
			<?php foreach ($listpages as $opt => $val) { ?>
		<option value="<?php echo $opt ;?>" <?php if ( $aboutpid  == $opt) { echo ' selected="selected" '; }?>><?php echo $val; ?></option>
		<?php } ?>
		</select>
		</label></p>
	<p><small><?php echo __('Your Services Page','centita');?></small>
		<select  name="<?php echo $this->get_field_name('servicespid'); ?>"  id="<?php echo $this->get_field_id('servicespid'); ?>" >
			<?php foreach ($listpages as $opt => $val) { ?>
		<option value="<?php echo $opt ;?>" <?php if ( $servicespid == $opt) { echo ' selected="selected" '; }?>><?php echo $val; ?></option>
		<?php } ?>
		</select>
		</label></p>
    <?php    
  } 
  
  function update($new_instance, $old_instance) {
    return $new_instance;
  }
  
  function widget( $args, $instance ) {
    global $post;
    
    extract($args);
    
    $companyinfotitle = apply_filters('companyinfotitle',$instance['companyinfotitle']);    
    $aboutpid = apply_filters('aboutpid',$instance['aboutpid']);
    $servicespid = apply_filters('servicespid',$instance['servicespid']);
    if ($companyinfotitle=="") $companyinfotitle = __("Company Profile",'centita');
    ?>
    <div class="sidebox-top"></div>
			<div class="sidebox">
  	<?php echo $before_title.$companyinfotitle.$after_title;?>
    <?php    
	  $aboutpage = new WP_Query('showposts=1&page_id='.$aboutpid); 
	  while ($aboutpage->have_posts()) : $aboutpage->the_post();
  	?>
  	<p><?php excerpt(20);?></p>
    <?php endwhile;?>
    <ul class="about-list">
    <?php
      $servicespage = new WP_Query('post_type=page&post_parent='.$servicespid); 
      while ($servicespage->have_posts()) : $servicespage->the_post();
    ?>                      
        <li><a href="<?php the_permalink();?>"><?php the_title();?></a></li>
      <?php endwhile;?>
    </ul>    
	</div><!-- end of sidebox -->
   <?php
   wp_reset_query();  
  } 
}

add_action('widgets_init', create_function('', 'return register_widget("CompanyInfo_Widget");'));

/* Page to Homepage Box or Sidebar Box Widget */

class PageToBox_Widget extends WP_Widget {
  
  function PageToBox_Widget() {
    $widgets_opt = array('class'=>'box','description'=>'Centita Theme Widget for displaying page as homepage box or sidebar box');
    parent::WP_Widget(false,$name= "Centita Page to Box",$widgets_opt);  
  }
  
  function form($instance) {
    global $post;
    
    $pageid = esc_attr($instance['pageid']);
    $check_opt = $instance['check_opt'];
    
		$pages = get_pages();
		$listpages = array();
		foreach ($pages as $pagelist ) {
		   $listpages[$pagelist->ID] = $pagelist->post_title;
		}
      ?>
	<p><small><?php echo __('Please select a page to display in box.','centita');?></small></p>
		<select  name="<?php echo $this->get_field_name('pageid'); ?>"  id="<?php echo $this->get_field_id('pageid'); ?>" >
			<?php foreach ($listpages as $opt => $val) { ?>
		<option value="<?php echo $opt ;?>" <?php if ( $pageid  == $opt) { echo ' selected="selected" '; }?>><?php echo $val; ?></option>
		<?php } ?>
		</select>
		</label></p>
  	<p>
		<input class="checkbox" type="checkbox" <?php if ($check_opt == "on") echo "checked";?> id="<?php echo $this->get_field_id('check_opt'); ?>" name="<?php echo $this->get_field_name('check_opt'); ?>" />
		<label for="<?php echo $this->get_field_id('check_opt'); ?>"><?php echo __('Show Image Thumbnail?','centita');?></label><br />
    </p>  	
	<?php
  }
  
  function update($new_instance, $old_instance) {				
      return $new_instance;
  }
  
  function widget( $args, $instance ) {
    global $post;
    
    extract($args);
    
    $pageid = apply_filters('pageid',$instance['pageid']);
    $check_opt = apply_filters('check_opt',$instance['check_opt']);
    if ($ID == 'homepagebox1' || $ID == 'homepagebox2' ) { ?>
      <div class="box-main">
      <?php
        query_posts('post_type=page&page_id='.$pageid);
        while (have_posts()) : the_post();      
        ?>
        <?php if ($check_opt == "on") { ?>
      	<div class="icon">
				<?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {?>
            <img src="<?php echo get_template_directory_uri();?>/timthumb.php?src=<?php echo thumb_url();?>&amp;h=90&amp;w=66&amp;zc=1" alt="" class="imgleft"/>
        <?php } ?>
      </div>
      <?php } ?>
      <p>
      <strong><a href="<?php the_permalink();?>"><?php echo the_title();?></a></strong><br />
      <?php excerpt(30);?>
      </p>
      <span class="read-more"><a href="<?php the_permalink();?>"><img src="<?php echo get_template_directory_uri();?>/images/read-more.gif" alt="" /></a></span>
      <br />
      <div class="clr"></div>              
      <?php endwhile;?>
      </div>
    <?php } else {
      echo $before_widget;
        $pagetitle = "<a href='".get_permalink($pageid)."'>".get_the_title($pageid)."</a>";
        echo $before_title.$pagetitle.$after_title;
        if ($pageid) {        
        query_posts('post_type=page&page_id='.$pageid);
        while (have_posts()) : the_post();
        ?>
        <?php if ($check_opt == "on") { ?>
        <div class="icon">
				<?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {?>
            <img src="<?php echo get_template_directory_uri();?>/timthumb.php?src=<?php echo thumb_url();?>&amp;h=60&amp;w=60&amp;zc=1" alt="" class="imgleft"/>
        <?php } ?>
        </div>
        <?php }?>
        <?php excerpt(30)."<br />";?>
        <span class="read-more"><a href="<?php the_permalink();?>"><img src="<?php echo get_template_directory_uri();?>/images/read-more.gif" alt="" /></a></span>
  
        <br />
        <div class="clr"></div>                        
        <?php 
        endwhile;
        wp_reset_query();
      }
      echo $after_widget;  
      
    }
  }
}

add_action('widgets_init', create_function('', 'return register_widget("PageToBox_Widget");'));

/* Post to Homepage Box or Sidebar Box Widget */

class PostToBox_Widget extends WP_Widget {
  
  function PostToBox_Widget() {
    $widgets_opt = array('class'=>'box','description'=>'Centita Theme Widget for displaying post as homepage box or sidebar box');
    parent::WP_Widget(false,$name= "Centita Post to Box",$widgets_opt);  
  }
  
  function form($instance) {
    global $post;
    
    $postid = esc_attr($instance['postid']);
    $check_opt = $instance['check_opt'];
    
		$centitaposts = get_posts('numberposts=-1')
		?>  
	<p><small><?php echo __('Please select a page to display in box.','centita');?></small></p>
			<select  name="<?php echo $this->get_field_name('postid'); ?>"  id="<?php echo $this->get_field_id('postid'); ?>" >
				<?php foreach ($centitaposts as $post) { ?>
			<option value="<?php echo $post->ID;?>" <?php if ( $postid  ==  $post->ID) { echo ' selected="selected" '; }?>><?php echo  the_title(); ?></option>
			<?php } ?>
			</select>
	</label></p>
  <p>
		<input class="checkbox" type="checkbox" <?php if ($check_opt == "on") echo "checked";?> id="<?php echo $this->get_field_id('check_opt'); ?>" name="<?php echo $this->get_field_name('check_opt'); ?>" />
		<label for="<?php echo $this->get_field_id('check_opt'); ?>"><small><?php echo __('Show Image Thumbnail?','centita');?></small></label><br />
    </p>	
	<?php
  }
  
  function update($new_instance, $old_instance) {				
      return $new_instance;
  }
  
  function widget( $args, $instance ) {
    global $post;
    
    extract($args);
    
    $postid = apply_filters('postid', $instance['postid']);
    $check_opt = apply_filters('check_opt', $instance['check_opt']);
    
    if ($ID == 'homepagebox1' || $ID == 'homepagebox2' ) { ?>
      <div class="box-main">
      <?php
        query_posts('p='.$postid);
        while (have_posts()) : the_post();      
        ?>
        <?php if ($check_opt == "on") { ?>
      	<div class="icon">
        <?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {?>
            <img src="<?php echo get_template_directory_uri();?>/timthumb.php?src=<?php echo thumb_url();?>&amp;h=90&amp;w=66&amp;zc=1" alt="" class="imgleft"/>
        <?php } ?>
        </div>
      <?php }?>
      <p>
      <strong><a href="<?php the_permalink();?>"><?php echo the_title();?></a></strong>
      <br />
      <?php excerpt(30);?>
      </p>
        <span class="read-more"><a href="<?php the_permalink();?>"><img src="<?php echo get_template_directory_uri();?>/images/read-more.gif" alt="" /></a></span>
      <br />
      <div class="clr"></div>              
      <?php endwhile;?>
      </div>

    <?php } else {
        echo $before_widget;
        $posttitle = "<a href='".get_permalink($postid)."'>".get_the_title($postid)."</a>";
        echo $before_title.$posttitle.$after_title;        
        query_posts('p='.$postid);
        while (have_posts()) : the_post();       
        ?>
        <?php if ($check_opt == "on") { ?>
        <div class="icon">
  				 <?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {?>
            <img src="<?php echo get_template_directory_uri();?>/timthumb.php?src=<?php echo thumb_url();?>&amp;h=60&amp;w=60&amp;zc=1" alt="" class="imgleft"/>
          <?php } ?>
          </div>
        <?php }?>
        <?php excerpt(30)."<br />";?>
        <span class="read-more"><a href="<?php the_permalink();?>"><img src="<?php echo get_template_directory_uri();?>/images/read-more.gif" alt="" /></a></span>
      <br />
      <div class="clr"></div>                      
        <?php  
        endwhile;
      echo $after_widget;
      wp_reset_query();
    }
  }
}

add_action('widgets_init', create_function('', 'return register_widget("PostToBox_Widget");'));
?>